import VCData from '../interface/VCData'

export function getAveScore(list: VCData[]): number {
  let sum = 0
  for (let i = 0; i < list.length; i++) {
    sum += list[i]['总分']
  }
  if (sum) {
    return Number((sum / list.length).toFixed(2))
  } else {
    return 0
  }
}
export function filterMonth(list: VCData[], month: string): VCData[] {
  switch (month) {
    case '二月':
      return list.filter((item: VCData) => {
        return item['日期'] <= 44985
      })
    case '三月':
      return list.filter((item: VCData) => {
        return item['日期'] > 44985 && item['日期'] <= 45016
      })
    case '四月':
      return list.filter((item: VCData) => {
        return item['日期'] > 45016 && item['日期'] <= 45044
      })
    case '五月':
      return list.filter((item: VCData) => {
        return item['日期'] > 45050 && item['日期'] <= 45077
      })
    case '六月':
      return list.filter((item: VCData) => {
        return item['日期'] > 45077 && item['日期'] <= 45106
      })
    case '七月':
      return list.filter((item: VCData) => {
        return item['日期'] > 45106
      })
    default:
      return []
  }
}
//按扣分项计算扣除分数之和
export function getVideoItemDeduct(sumData: VCData[]) {
  const progress = { name: '课程进度和顺序是否符合大纲(20)', value: 0 }
  const flow = { name: '是否按照授课流程上课(10)', value: 0 }
  const content = { name: '授课内容是否符合大纲(40)', value: 0 }
  const effect = { name: '授课效果(20)', value: 0 }
  const video = { name: '视频质量(10)', value: 0 }
  for (let i = 0; i < sumData.length; i++) {
    progress.value += (20 - Number(sumData[i][progress.name]))
    flow.value += (10 - Number(sumData[i][flow.name]))
    content.value += (40 - Number(sumData[i][content.name]))
    effect.value += (20 - Number(sumData[i][effect.name]))
    video.value += (10 - Number(sumData[i][video.name]))
  }
  return {
    sum: [progress, flow, content, effect, video],
    ave: [
      Number((Number(progress.value) / sumData.length).toFixed(2)),
      Number((Number(flow.value) / sumData.length).toFixed(2)),
      Number((Number(content.value) / sumData.length).toFixed(2)),
      Number((Number(effect.value) / sumData.length).toFixed(2)),
      Number((Number(video.value) / sumData.length).toFixed(2))
    ]
  }
}
export function getCameraItemDeduct(sumData: VCData[]) {
  const tea = { name: '讲师在班状态(40)', value: 0 }
  const share = { name: '课前分享情况(10)', value: 0 }
  const student = { name: '学员上课状态(50)', value: 0 }
  for (let i = 0; i < sumData.length; i++) {
    tea.value += (40 - Number(sumData[i][tea.name]))
    share.value += (10 - Number(sumData[i][share.name]))
    student.value += (50 - Number(sumData[i][student.name]))
  }
  return {
    sum: [tea, share, student],
    ave: [
      Number((Number(tea.value) / sumData.length).toFixed(2)),
      Number((Number(share.value) / sumData.length).toFixed(2)),
      Number((Number(student.value) / sumData.length).toFixed(2))
    ]
  }
}